package com.jida.hadoop.mr.user8;

import com.jida.hadoop.mr.tools.TProperties;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
 
import java.io.IOException;
 
/**
 * 整体的产品统计：统计产品对应的用户访问量(UV),行为数据访问总量(PV)
 * 产生结果集：{产品ID,UV数(用户数),PV数(总访问量),产品类型}
 */
public class MapperDxProStatisticAll extends Mapper<LongWritable,Text,Text,Text>{
    private Text k2 = new Text();
    private Text v2 = new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //{产品ID,UV数(用户数),PV数(总访问量),产品类型}
        String[] values = value.toString().split(TProperties.getValue("fileoutsplit"));
        //产品id，产品类型
        k2.set(values[0] + TProperties.getValue("outfilesplit") + values[3]);
        //用户id，访问次数
        v2.set( values[1] + TProperties.getValue("outfilesplit") + values[2]);
        context.write(k2, v2);
 
        /*String[] psa = value.toString().split("\\|");
        k2.set(psa[0]);
        v2.set(psa[2]+","+psa[3]+","+1);
        context.write(k2,v2);*/
    }
}
